package laps.dataaccess.mysql;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.mysql.jdbc.jdbc2.optional.StatementWrapper;

import laps.dataaccess.CompensatableDaysDAO;
import laps.model.Employee;

public class CompensatableDaysDAOImpl implements CompensatableDaysDAO {
	
	private Connection connection;

	public CompensatableDaysDAOImpl(Connection connection) {
		super();
		this.connection = connection;
	}

	@Override
	public double getCompensatableDays(Employee employee, int year) {
		
		double compensatableDays = 0.0;
		int employeeID = employee.getEmployee_id();
		int yr = year;
		
		String sqlStatement = "select compensatable_days from "+
							  "laps_db.employee_compensatable_days where " +
							  "employee_id=" + employeeID + " and " +
							  "year=" + yr;
		
		Statement statement = null;
		ResultSet resultSet = null;
		
		try
		{
			statement = connection.createStatement();
			resultSet = statement.executeQuery(sqlStatement);
			compensatableDays = resultSet.getDouble("compensatable_days");
		}
		catch (SQLException e)
		{
			e.printStackTrace();
		}
		
		return compensatableDays;
	}

}
